<?php

/**
 * 文件由尚数增量代码引擎生成
 * @author: Shann 851188611@qq.com
 */

namespace app\admin\controller;

class MenuBase
{
    public function index()
    {
        $menus = \app\model\Menu::field(['id', 'label', 'name', 'path', 'icon', 'visible', 'sort']);

        $menus->order('id', 'desc');

        $data['menus'] = $menus->select();

        return json(['code' => 20000, 'data' => $data]);
    }

    public function detail()
    {
        $menu = \app\model\Menu::field(['id', 'label', 'name', 'path', 'icon', 'visible', 'sort']);

        $menu->where('id', input('id'));

        $data['menu'] = $menu->find();

        return json(['code' => 20000, 'data' => $data]);
    }

    public function create()
    {
        $param = request()->param();

        $model = new \app\model\Menu();

        $model->save($param);

        $data['menu'] = \app\model\Menu::find($model->id);

        return json(['code' => 20000, 'msg' => 'success', 'data' => $data]);
    }

    public function update()
    {
        $param = request()->param();

        $model = \app\model\Menu::find(input('id'));

        $model->save($param);

        return json(['code' => 20000, 'msg' => 'success']);
    }

    public function delete()
    {
        \app\model\Menu::destroy(function ($query) {
            $query->where('id', input('id'));
        });

        return json(['code' => 20000, 'msg' => 'success']);
    }
}
